package kr.saeildamil.androidstudy_second.actionbar;

import kr.saeildamil.andrordstudy.second.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MenuItem.OnActionExpandListener;
import android.view.View;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.TextView;

public class ActionView extends Activity {
	MenuItem mSearch;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch21_actionview);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.actionviewmenu, menu);
		mSearch = menu.findItem(R.id.search);
		
		mSearch.setOnActionExpandListener(new OnActionExpandListener() {
			public boolean onMenuItemActionExpand(MenuItem item) {
				TextView text = (TextView) findViewById(R.id.ch21_actionview_txtstatus);
				text.setText("현재 상태 : 확장됨");
				return true;
			}

			public boolean onMenuItemActionCollapse(MenuItem item) {
				TextView text = (TextView) findViewById(R.id.ch21_actionview_txtstatus);
				text.setText("현재 상태 : 축소됨");
				return true;
			}
		});
		
		SearchView sv = (SearchView) mSearch.getActionView();
		sv.setOnQueryTextListener(new OnQueryTextListener() {
			public boolean onQueryTextSubmit(String query) {
				TextView text = (TextView) findViewById(R.id.ch21_actionview_txtresult);
				text.setText(query + "를 검색합니다.");
				return true;
			}
			public boolean onQueryTextChange(String newText) {
				TextView text = (TextView) findViewById(R.id.ch21_actionview_txtsearch);
				text.setText("검색식 : " + newText);
				return true;
			}
		});
		
		return true;
	}
	
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.ch21_actionview_btnexpand:
			mSearch.expandActionView();
			break;
		case R.id.ch21_actionview_btncollapse:
			mSearch.collapseActionView();
			break;
		}
	}
}
